Skip to main content

存储能力

首选项

使用“首选项”可方便地处理简单的数据片段(如用户选择)。 它们通常用于使用户能够配置应用程序。 将此数据存储为一组键/值对。

bool saveLoginDetails = ...;
...
Preferences.Set("SaveLogin", saveLoginDetails);
...
var savedPreference = Preferences.Get("SaveLogin", false);

文件系统

using System.Text.Json;
using System.IO;

// Data to be written to the file system, and read back later
List<Customer> customers = ...;

// Serialize and save
string fileName = ...;
var serializedData = JsonSerializer.Serialize(customers);
File.WriteAllText(fileName, serializedData);
...

// Read and deserialize
var rawData = File.ReadAllText(fileName);
customers = JsonSerializer.Deserialize<List<Customer>>(rawData);

应用沙盒

string path = FileSystem.AppDataDirectory;

SQLite数据库

需要Nuget包

  • sqlite-net-pcl
  • SQLitePCLRaw.bundle_green(为了安卓应用)